package com.yoso.controller;

import com.yoso.core.dto.ResponseResult;
import com.yoso.file.sdk.response.UploadResponse;
import com.yoso.file.sdk.upload.UploadFile;
import com.yoso.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UploadController {
    @Autowired
    private UploadFile uploadFile;

    @PostMapping("/upload")
    public Object upload(MultipartHttpServletRequest request) throws Exception {
        List<UploadResponse> results = new ArrayList<UploadResponse>();
        request.getFileMap().forEach((key, file) ->{
            System.out.println("key = " + key);
            System.out.println("file = " + file.getOriginalFilename());
            results.add(uploadFile.upload(file));
        });
        return ResponseResult.success(results);
    }
}
